package com.gomyb.admin.web.controller;

import com.gomyb.storage.StorageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/3/6 18:14
 */
@RestController
@RequestMapping(value = "/file", name = "文件上传")
public class FileController {

    @Autowired
    private StorageHandler storageHandler;

    @PostMapping("/upload")
    public void upload(MultipartFile file) {
        try {
            InputStream stream = file.getInputStream();
            storageHandler.upload(stream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
